<?php

	$vstatus=$_REQUEST['vstatus'];
	$vstartdate=$_REQUEST['vstartdate'];
	$venddate=$_REQUEST['venddate'];
	$vtimediff=$_REQUEST['vtimediff'];
	$vspeed=$_REQUEST['vspeed'];
	$vdistance=$_REQUEST['vdistance'];
	$vremark=$_REQUEST['vremark'];
	$vsensor=$_REQUEST['vsensor'];

require("./fpdf153/fpdf.php");
class PDF extends FPDF
{
	/*function picturelogo($logo,$x,$y,$size){
		//image
		$this->Image($logo,$x,$y,$size);
	}*/
	/*function Header(){
		global $titlemain,$ys;
		//SetY
		$this->SetY(($ys-15));
		//Tahoma 12
		$this->SetFont('tahoma','',11);
		//Title
		$this->Cell(0,8,$titlemain,0,1,'C');
		//Line break
		$this->Ln(20);
	}*/

	/*function imagebit()
	{
		global $logo,$x,$y,$size,$n;
		//image
		$this->Image($logo,$x,$y,$size);
	}*/
	function Printrows($width,$hight, $data, $xcell, $ycell, $r, $g, $b, $align,$header)
	{
		//global $ycell;
		$this->SetXY($xcell,$ycell);
		//Tahoma
		if($header==1){
			$this->SetFont('Tahomab','',9);
		}else{
			$this->SetFont('Tahoma','',9);
		}
		//Background color
		$this->SetFillColor($r,$g,$b);
		//Title
		$this->Cell($width,$hight,$data,0,1,$align,1);
		//Line break
		$this->Ln();
		//$this->ChapterBody($file);
	}
	/*function textshow($xt,$yt,$datastr){
		$this->SetFont('tahoma','',9);
		$this->Text($xt,$yt,$datastr);
	}*/
	function Footer()
		{
		//Position at 1.5 cm from bottom
		$this->SetY(-15);
		//Arial italic 8
		$this->SetFont('Arial','I',8);
		//Page number
		$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
	}
}
	$pdf=new PDF($orientation='L');
	$pdf->Open();
	$pdf->AliasNbPages();
	$pdf->AddPage();
	//$pdf->AddFont('Angsana','','angsana.php');
	$pdf->AddFont('Tahoma','','tahoma.php');
	$pdf->AddFont('Tahomab','','tahomab.php');
	//$valuemain=array($vstatus, $vstartdate, $venddate, $vtimediff, $vspeed);

			//$xcell=20; $ycell=30;
		$i=0;
		foreach($vstatus as $statusv){
			$vstatus[$i]=$statusv; $i++;
		}
		$i=0;
		foreach($vstartdate as $startdatev){
			$vstartdate[$i]=$startdatev; $i++;
		}
		$i=0;
		foreach($venddate as $enddatev){
			$venddate[$i]=$enddatev; $i++;
		}
		$i=0;
		foreach($vtimediff as $timediffv){
			$vtimediff[$i]=$timediffv; $i++;
		}
		$i=0;
		foreach($vspeed as $speedv){
			$vspeed[$i]=$speedv; $i++;
		}
		$i=0;
		foreach($vdistance as $distancev){
			$vdistance[$i]=$distancev; $i++;
		}
		$i=0;
		foreach($vremark as $remarkv){
			$vremark[$i]=$remarkv; $i++;
		}
		$i=0;
		foreach($vsensor as $sensorv){
			$vsensor[$i]=$sensorv; $i++;
		}	
			$ytext=40; 
			$xstatus=20;
			$xstartdate=40;
			$xenddate=70;
			$xtimediff=95;
			$xspeed=120;
			$xdistance=130;
			$xlocate=165;
			$xstatussensor=230;
			$pdf->Printrows(($xstartdate-$xstatus), 6, 'Status', $xstatus, ($ytext-6), 100, 149, 237,'C',1);
			$pdf->Printrows(($xenddate-$xstartdate), 6, 'Start Date/Time', $xstartdate, ($ytext-6), 100, 149, 237,'C',1);
			$pdf->Printrows(($xtimediff-$xenddate), 6, 'End Date/Time', $xenddate, ($ytext-6), 100, 149, 237,'C',1);
			$pdf->Printrows(($xspeed-$xtimediff), 6, 'Duration.', $xtimediff, ($ytext-6), 100, 149, 237,'C',1);
			$pdf->Printrows(($xdistance-$xspeed+6), 6, 'Max Speed.', $xspeed, ($ytext-6), 100, 149, 237,'C',1);
			$pdf->Printrows(($xlocate-$xdistance-6), 6, 'Distance (km.)', ($xdistance+5), ($ytext-6), 100, 149, 237,'C',1);
			$pdf->Printrows(($xstatussensor-$xlocate+3), 6, 'Remark', ($xlocate-3), ($ytext-6), 100, 149, 237,'C',1);
			$pdf->Printrows(50, 6, 'ʶҹТͧ sensor', $xstatussensor, ($ytext-6), 100, 149, 237,'L',1);
		for($rows=0;$rows<count($vstatus);$rows++){
			if(($rows%2)==0){ $r1=245; $g1=245; $b1=245; }else{ $r1=255; $g1=255; $b1=255;}
					$pdf->Printrows(($xstartdate-$xstatus),6, $vstatus[$rows], $xstatus, $ytext, $r1, $g1, $b1,'L',0);
					$pdf->Printrows(($xenddate-$xstartdate),6, $vstartdate[$rows], $xstartdate, $ytext, $r1, $g1, $b1,'C',0);
					$pdf->Printrows(($xtimediff-$xenddate),6, $venddate[$rows], $xenddate, $ytext, $r1, $g1, $b1,'C',0);
					$pdf->Printrows(($xspeed-$xtimediff),6, $vtimediff[$rows], $xtimediff, $ytext, $r1, $g1, $b1,'C',0);
					$pdf->Printrows(($xdistance-$xspeed),6, $vspeed[$rows], $xspeed, $ytext, $r1, $g1, $b1,'C',0);
					$pdf->Printrows(($xlocate-$xdistance),6, $vdistance[$rows], $xdistance, $ytext, $r1, $g1, $b1,'C',0);
					$pdf->Printrows(($xstatussensor-$xlocate),6, $vremark[$rows], $xlocate, $ytext, $r1, $g1, $b1,'L',0);
					$pdf->Printrows(50,6, $vsensor[$rows], $xstatussensor, $ytext, $r1, $g1, $b1,'L',0);
					$ytext=$ytext+6;
					if($ytext>=184){ 
						$pdf->AddPage(); $ytext=40; 
						$pdf->Printrows(($xstartdate-$xstatus), 6, 'Status', $xstatus, ($ytext-6), 100, 149, 237,'C',1);
						$pdf->Printrows(($xenddate-$xstartdate), 6, 'Start Date/Time', $xstartdate, ($ytext-6), 100, 149, 237,'C',1);
						$pdf->Printrows(($xtimediff-$xenddate), 6, 'End Date/Time', $xenddate, ($ytext-6), 100, 149, 237,'C',1);
						$pdf->Printrows(($xspeed-$xtimediff), 6, 'Duration.', $xtimediff, ($ytext-6), 100, 149, 237,'C',1);
						$pdf->Printrows(($xdistance-$xspeed+5), 6, 'Max Speed.', $xspeed, ($ytext-6), 100, 149, 237,'C',1);
						$pdf->Printrows(($xlocate-$xdistance-5), 6, 'Distance (km.)', $xdistance+5, ($ytext-6), 100, 149, 237,'C',1);
						$pdf->Printrows(($xstatussensor-$xlocate+3), 6, 'Remark', $xlocate-3, ($ytext-6), 100, 149, 237,'C',1);
						$pdf->Printrows(50, 6, 'ʶҹТͧ sensor', $xstatussensor, ($ytext-6), 100, 149, 237,'L',1);
					}
		}
	$pdf->Output();
?>